package boot.service;

import boot.dao.SupplierRepository;
import boot.entity.Supplier;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SupplierService {
    @Autowired
    private SupplierRepository repository;

    public void save(Supplier supplier) {
        repository.save(supplier);
    }

    public void deleteById(int id){
        repository.deleteById(id);
    }

    public void deleteAll(){
        repository.deleteAll();
    }

    public Supplier getById(int id){
        return repository.findById(id);
    }

    public List<Supplier> getByName(String name){
        return repository.findByName(name);
    }

    public List<Supplier> getByNameContaining(String name){
        return repository.findByNameContaining(name);
    }

    public List<Supplier> getByStockAfter(int stock){
        return repository.findByStockAfter(stock);
    }

    public List<Supplier> getByNameAndStock(String name, int stock){
        return repository.findWithJPQLByNameAndStock(name, stock);
    }
}
